const { CleanWebpackPlugin } = require("clean-webpack-plugin");
const HtmlWebpackPlugin = require("html-webpack-plugin");
const CopyPlugin = require("copy-webpack-plugin");

module.exports = {
  mode: "development",
  devtool: "source-map",
  output: {
    filename: "scripts/[name].[chunkhash:5].js",
  },
  plugins: [
    new CleanWebpackPlugin(),
    new HtmlWebpackPlugin({
      template: "./public/index.html",
    }),
    new CopyPlugin([{ from: "./public", to: "./" }]),
  ],
  devServer: {
    port: "8000",
    open: true,
    index: "index.html",
    proxy: {
      //代理规则
      "/test": {
        target: "https://cnodejs.org",
        changeOrigin: true, //更改请求头中的host和origin
        pathRewrite: { "^/test": "" },
      },
    },
  },
};
